<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="搬砖 嵌入式">
<meta property="og:type" content="website">
<meta property="og:title" content="学无止境">
<meta property="og:url" content="http://example.com/page/14/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="搬砖 嵌入式">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="xudonglei">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/page/14/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/12/06/python%E4%B8%8D%E4%BB%A5%E7%A7%91%E5%AD%A6%E8%AE%A1%E6%95%B0%E6%B3%95%E8%BE%93%E5%87%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/12/06/python%E4%B8%8D%E4%BB%A5%E7%A7%91%E5%AD%A6%E8%AE%A1%E6%95%B0%E6%B3%95%E8%BE%93%E5%87%BA/" class="post-title-link" itemprop="url">python不以科学计数法输出</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-12-06 16:01:33" itemprop="dateCreated datePublished" datetime="2022-12-06T16:01:33+08:00">2022-12-06</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2022/12/06/python%E4%B8%8D%E4%BB%A5%E7%A7%91%E5%AD%A6%E8%AE%A1%E6%95%B0%E6%B3%95%E8%BE%93%E5%87%BA/" class="post-meta-item leancloud_visitors" data-flag-title="python不以科学计数法输出" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/12/06/python%E4%B8%8D%E4%BB%A5%E7%A7%91%E5%AD%A6%E8%AE%A1%E6%95%B0%E6%B3%95%E8%BE%93%E5%87%BA/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/12/06/python%E4%B8%8D%E4%BB%A5%E7%A7%91%E5%AD%A6%E8%AE%A1%E6%95%B0%E6%B3%95%E8%BE%93%E5%87%BA/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>   其实很简单只需两个语句：</p>
<p>​    import numpy as np<br>​    np.set_printoptions(suppress=True)    </p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/31/stm32f427%E7%A7%BB%E6%A4%8Dfreertos/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/31/stm32f427%E7%A7%BB%E6%A4%8Dfreertos/" class="post-title-link" itemprop="url">stm32f427移植freertos</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-31 21:21:24" itemprop="dateCreated datePublished" datetime="2022-10-31T21:21:24+08:00">2022-10-31</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/31/stm32f427%E7%A7%BB%E6%A4%8Dfreertos/" class="post-meta-item leancloud_visitors" data-flag-title="stm32f427移植freertos" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/31/stm32f427%E7%A7%BB%E6%A4%8Dfreertos/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/31/stm32f427%E7%A7%BB%E6%A4%8Dfreertos/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>1.下载FreeRTOS源码，可以从官网下载源码，官网地址：<a target="_blank" rel="noopener" href="https://www.freertos.org/a00104.html">https://www.freertos.org/a00104.html</a></p>
<p>2.解压后包含的内容比较丰富，不过目录结构很清晰，主要包含两个子目录：FreeRTOS和FreeRTOS-Plus。如下所示：</p>
<p>FreeRTOS-Plus       包含FreeRTOS+组件和演示例程；<br>FreeRTOS                包含FreeRTOS实时内核源文件和演示例程。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312132699.png" style="zoom:60%;">

<p>RTOS代码的核心包含在三个文件中：tasks.c、queue.c、list.c。这三个文件位于FreeRTOS/Source目录。在该目录下还包含三个可选的文件：timers.c、event_groups.c、croutine.c，分别实现软件定时、事件组和协程功能。</p>
<p>3.需要用到的文件</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312151887.png" style="zoom:57%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312155762.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312155560.png" style="zoom:67%;">

<p>4.移植到keil工程里</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312206665.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312207796.png" style="zoom:67%;">

<p>5.在FreeRTOS的官方移植工程Demo文件夹下，找到CORTEX_M4F_STM32F407ZG-SK文件夹，打开找到里面的FreeRTOSConfig.h文件，添加到工程文件FreeRTOS文件夹下的include文件夹里。</p>
<p>​        并修改 freeRTOS 配置文件 FreeRTOSConfig.h，在这里配置 stm32 单片机的系统时钟，这里配置为168MHz，配置系统调度时间片，这里设置为 1000Hz 即 1ms 的时间片。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312247610.png" style="zoom:67%;">

<p>然后编译，如果出现 …\FreeRTOS\queue.c(2762): error: #268: declaration may not appear after executable statement in block 的问题，在Keil的魔术棒中C/C++选项卡下选择C99mode即可。<br>        然后系统会提示出现三个 error 信号：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312250212.png"></p>
<p>这时我们到中断文件stm32f4xx_it.c中将这三个函数屏蔽掉即可。</p>
<p>​        <strong>特别说明：</strong>在前面说过FreeRTOSConfig.h 配置文件中，有上面3个宏定义。该宏定义避免了修改启动文件，但有一个地方需要注意一下。就是第3个宏定义“#define xPortSysTickHandler       SysTick_Handler”。如果采用的是ST的标准库没有问题，但如果采用的是HAL库，<strong>由于HAL库需要SysTick中断才能稳定运行，所以不能采用宏定义，而是在stm32f4xx_it.c文件中的SysTick中断响应函数中调用xPortSysTickHandler函数</strong>。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312324990.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210312328621.png" style="zoom:67%;">

<p>6.复制过来的FreeRTOSConfig.h文件中默认开启了一些钩子函数，都是以Hook结尾，但并未定义，在FreeRTOSConfig.h中把configUSE_IDLE_HOOK、configUSE_TICK_HOOK、configCHECK_FOR_STACK_OVERFLOW和MALLOC_FAILED_HOOK的宏定义改为0</p>
<p>7.写代码验证任务调度</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;FreeRTOS.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;task.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TASK1_PRIORITY 1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TASK1_STACK_SIZE 512</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TASK2_PRIORITY 2</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> TASK2_STACK_SIZE 512</span></span><br><span class="line"></span><br><span class="line">TaskHandle_t task1_handler;</span><br><span class="line">TaskHandle_t task2_handler;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">task1</span><span class="params">(<span class="keyword">void</span> * pvParameters)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (;;) </span><br><span class="line">	&#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%s\n&quot;</span>, <span class="string">&quot;task1&quot;</span>);</span><br><span class="line">        vTaskDelay(<span class="number">1000</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">task2</span><span class="params">(<span class="keyword">void</span> * pvParameters)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (;;) </span><br><span class="line">	&#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%s\n&quot;</span>, <span class="string">&quot;task2&quot;</span>);</span><br><span class="line">        vTaskDelay(<span class="number">2000</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="keyword">char</span> <span class="title">task_init</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    BaseType_t status = pdPASS;</span><br><span class="line"></span><br><span class="line">    status = xTaskCreate(task1,</span><br><span class="line">            <span class="string">&quot;task1&quot;</span>,</span><br><span class="line">            TASK1_STACK_SIZE,</span><br><span class="line">            <span class="literal">NULL</span>,</span><br><span class="line">            TASK1_PRIORITY,</span><br><span class="line">            &amp;task1_handler);</span><br><span class="line"></span><br><span class="line">    status = xTaskCreate(task2,</span><br><span class="line">            <span class="string">&quot;task2&quot;</span>,</span><br><span class="line">            TASK2_STACK_SIZE,</span><br><span class="line">            <span class="literal">NULL</span>,</span><br><span class="line">            TASK2_PRIORITY,</span><br><span class="line">            &amp;task2_handler);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> status;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	target_init(); <span class="comment">//硬件有关的初始化</span></span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span> (task_init() == pdPASS)</span><br><span class="line">	&#123;</span><br><span class="line">        vTaskStartScheduler();</span><br><span class="line">	&#125;</span><br><span class="line">    <span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/23/FSMC%E6%89%A9%E5%B1%95%E5%A4%96%E9%83%A8SRAM/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/23/FSMC%E6%89%A9%E5%B1%95%E5%A4%96%E9%83%A8SRAM/" class="post-title-link" itemprop="url">FSMC扩展外部SRAM</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-23 21:26:57" itemprop="dateCreated datePublished" datetime="2022-10-23T21:26:57+08:00">2022-10-23</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/23/FSMC%E6%89%A9%E5%B1%95%E5%A4%96%E9%83%A8SRAM/" class="post-meta-item leancloud_visitors" data-flag-title="FSMC扩展外部SRAM" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/23/FSMC%E6%89%A9%E5%B1%95%E5%A4%96%E9%83%A8SRAM/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/23/FSMC%E6%89%A9%E5%B1%95%E5%A4%96%E9%83%A8SRAM/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://doc.embedfire.com/mcu/stm32/f4/hal_general/zh/latest/doc/chapter26_0/chapter26_0.html">https://doc.embedfire.com/mcu/stm32/f4/hal_general/zh/latest/doc/chapter26_0/chapter26_0.html</a></p>
<h3 id="SRAM信号线"><a href="#SRAM信号线" class="headerlink" title="SRAM信号线"></a>SRAM信号线</h3><table>
<thead>
<tr>
<th>信号线</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>A0-A18</td>
<td>I</td>
<td>地址输入</td>
</tr>
<tr>
<td>I/O0-I/O7</td>
<td>I/O</td>
<td>数据输入输出信号，低字节</td>
</tr>
<tr>
<td>I/O8-I/O15</td>
<td>I/O</td>
<td>数据输入输出信号，高字节</td>
</tr>
<tr>
<td>CS和CS1#</td>
<td>I</td>
<td>片选信号，CS2高电平有效，CS1#低电平有效，部分芯片只有其中一个引脚</td>
</tr>
<tr>
<td>OE#</td>
<td>I</td>
<td>输出使能信号，低电平有效</td>
</tr>
<tr>
<td>WE#</td>
<td>I</td>
<td>写入使能，低电平有效</td>
</tr>
<tr>
<td>UB#</td>
<td>I</td>
<td>数据掩码信号Upper Byte，高位字节允许访问，低电平有效</td>
</tr>
<tr>
<td>LB#</td>
<td>I</td>
<td>数据掩码信号Lower Byte，低位字节允许访问，低电平有效</td>
</tr>
</tbody></table>
<p>​        SRAM的控制比较简单，只要控制信号线使能了访问，从地址线输入要访问的地址，即可从I/O数据线写入或读出数据。</p>
<h3 id="控制电路"><a href="#控制电路" class="headerlink" title="控制电路"></a>控制电路</h3><p>​        控制电路主要包含了片选、读写使能以及上面提到的宽度控制信号UB#和LB#。利用CS2或CS1#片选信号，可以把多个SRAM芯片组成一个大容量的内存条。OE#和WE#可以控制读写使能，防止误操作。</p>
<h3 id="SRAM的读写流程"><a href="#SRAM的读写流程" class="headerlink" title="SRAM的读写流程"></a>SRAM的读写流程</h3><p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20221023213318.png"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20221023213345.png"></p>
<p>读写时序的流程很类似，下面我们统一解说：</p>
<ol>
<li><p>主机使用地址信号线发出要访问的存储器目标地址；</p>
</li>
<li><p>控制片选信号CS1#及CS2#使能存储器芯片；</p>
</li>
<li><p>若是要进行读操作，则控制读使能信号OE#表示要读数据，若进行写操作则控制写使能信号WE#表示要写数据；</p>
</li>
<li><p>使用掩码信号LB#与UB#指示要访问目标地址的高、低字节部分；</p>
</li>
<li><p>若是读取过程，存储器会通过数据线向主机输出目标数据，若是写入过程，主要使用数据线向存储器传输目标数据。</p>
</li>
</ol>
<p>​        在读写时序中，有几个比较重要的时间参数，在使用STM32 控制的时候需要参考，它们的介绍见表 26‑2。</p>
<table>
<thead>
<tr>
<th>时间参数</th>
<th>IS62WV51216BLL-55ns型号的时间要求</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>tRC</td>
<td>不小于55ns</td>
<td>读操作的总时间</td>
</tr>
<tr>
<td>tAA</td>
<td>最迟不大于55ns</td>
<td>从接收到地址信号到给出有效数据的时间</td>
</tr>
<tr>
<td>tDOE</td>
<td>最迟不大于25ns</td>
<td>从接收到读使能信号到给出有效数据的时间</td>
</tr>
<tr>
<td>tWC</td>
<td>不小于55ns</td>
<td>写操作的总时间</td>
</tr>
<tr>
<td>tSA</td>
<td>大于0ns</td>
<td>从发送地址信号到给出写有使能信号的时间</td>
</tr>
<tr>
<td>tPWE</td>
<td>不小于40ns</td>
<td>从接收到写使能信号到数据采样的时间</td>
</tr>
</tbody></table>
<h3 id="FSMC中的SRAM控制信号线"><a href="#FSMC中的SRAM控制信号线" class="headerlink" title="FSMC中的SRAM控制信号线"></a>FSMC中的SRAM控制信号线</h3><table>
<thead>
<tr>
<th>FSMC引脚名称</th>
<th>对应SRAM引脚名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>FSMC_NBL[1:0]</td>
<td>LB#、UB#</td>
<td>数据掩码信号</td>
</tr>
<tr>
<td>FSMC_A[18:0]</td>
<td>A[18:0]</td>
<td>行地址线</td>
</tr>
<tr>
<td>FSMC_D[15:0]</td>
<td>I/O[15:0]</td>
<td>数据线</td>
</tr>
<tr>
<td>FSMC_NWE</td>
<td>WE#</td>
<td>写入使能</td>
</tr>
<tr>
<td>FSMC_NOE</td>
<td>OE#</td>
<td>输出使能(读使能)</td>
</tr>
<tr>
<td>FSMC_NE[1:4]</td>
<td>CE#</td>
<td>片选信号</td>
</tr>
</tbody></table>
<p>​        其中比较特殊的FSMC_NE是用于控制SRAM芯片的片选控制信号线，STM32具有FSMC_NE1/2/3/4号引脚，不同的引脚对应STM32内部不同的地址区域。例如，当STM32访问0x6C000000-0x6FFFFFFF地址空间时，FSMC_NE3引脚会自动设置为低电平，由于它连接到SRAM的CE#引脚，所以SRAM的片选被使能，而访问0x60000000-0x63FFFFFF地址时，FSMC_NE1会输出低电平。当使用不同的FSMC_NE引脚连接外部存储器时，STM32访问SRAM的地址不一样，从而达到控制多块SRAM芯片的目的。</p>
<h3 id="FSMC控制SRAM的时序"><a href="#FSMC控制SRAM的时序" class="headerlink" title="FSMC控制SRAM的时序"></a>FSMC控制SRAM的时序</h3><p>​        FSMC外设支持输出多种不同的时序以便于控制不同的存储器，它具有ABCD四种模式，下面我们仅针对控制SRAM使用的模式A进行讲解</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20221023213842.png" style="zoom:70%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20221023213921.png" style="zoom:70%;">

<p>​        当内核发出访问某个指向外部存储器地址时，FSMC外设会根据配置控制信号线产生时序访问存储器，上图中的是访问外部SRAM时FSMC外设的读写时序。</p>
<p>​        以读时序为例，该图表示一个存储器操作周期由地址建立周期(ADDSET)、数据建立周期(DATAST)以及2个HCLK周期组成。在地址建立周期中，地址线发出要访问的地址，数据掩码信号线指示出要读取地址的高、低字节部分，片选信号使能存储器芯片；地址建立周期结束后读使能信号线发出读使能信号，接着存储器通过数据信号线把目标数据传输给FSMC，FSMC把它交给内核。</p>
<p>​        写时序类似，区别是它的一个存储器操作周期仅由地址建立周期(ADDSET)和数据建立周期(DATAST)组成，且在数据建立周期期间写使能信号线发出写信号，接着FSMC把数据通过数据线传输到存储器中。</p>
<h3 id="SRAM时序结构体"><a href="#SRAM时序结构体" class="headerlink" title="SRAM时序结构体"></a>SRAM时序结构体</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">   <span class="keyword">uint32_t</span> FSMC_AddressSetupTime;       <span class="comment">/*地址建立时间，0-0xF个HCLK周期*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> FSMC_AddressHoldTime;        <span class="comment">/*地址保持时间，0-0xF个HCLK周期*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> FSMC_DataSetupTime;           <span class="comment">/*地址建立时间，0-0xF个HCLK周期*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> FSMC_BusTurnAroundDuration;<span class="comment">/*总线转换周期,0-0xF个HCLK周期，在NOR FLASH */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> FSMC_CLKDivision;<span class="comment">/*时钟分频因子,1-0xF，若控制异步存储器，本参数无效 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> FSMC_DataLatency;    <span class="comment">/*数据延迟时间，若控制异步存储器，本参数无效 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> FSMC_AccessMode;             <span class="comment">/*设置访问模式 */</span></span><br><span class="line">&#125;FSMC_NORSRAMTimingInitTypeDef;</span><br></pre></td></tr></table></figure>
<ol>
<li>FSMC_AddressSetupTime</li>
</ol>
<blockquote>
<p>本成员设置地址建立时间，即FSMC读写时序中的ADDSET值，它可以被设置为0-0xF个HCLK周期数，按STM32HAL库的默认配置，HCLK的时钟频率为168MHz，即一个HCLK周期为1/168微秒。</p>
</blockquote>
<ol>
<li>FSMC_AddressHoldTime</li>
</ol>
<blockquote>
<p>本成员设置地址保持时间，它可以被设置为0-0xF个HCLK周期数。</p>
</blockquote>
<ol>
<li>FSMC_DataSetupTime</li>
</ol>
<blockquote>
<p>本成员设置数据建立时间，即FSMC读写时序中的DATAST值，它可以被设置为0-0xF个HCLK周期数。</p>
</blockquote>
<ol>
<li>FSMC_BusTurnAroundDuration</li>
</ol>
<blockquote>
<p>本成员设置总线转换周期，在NOR FLASH存储器中，地址线与数据线可以分时复用，总线转换周期就是指总线在这两种状态间切换需要的延时， 防止冲突。控制其它存储器时这个参数无效，配置为0即可。</p>
</blockquote>
<ol>
<li>FSMC_CLKDivision</li>
</ol>
<blockquote>
<p>本成员用于设置时钟分频，它以HCLK时钟作为输入，经过FSMC_CLKDivision分频后输出到FSMC_CLK引脚作为通讯使用的同步时钟。控制其它异步通讯的存储器时这个参数无效，配置为0即可。</p>
</blockquote>
<ol>
<li>FSMC_DataLatency</li>
</ol>
<blockquote>
<p>本成员设置数据保持时间，它表示在读取第一个数据之前要等待的周期数，该周期指同步时钟的周期，本参数仅用于同步NOR FLASH类型的存储器，控制其它类型的存储器时，本参数无效。</p>
</blockquote>
<ol>
<li>FSMC_AccessMode</li>
</ol>
<blockquote>
<p>本成员设置存储器访问模式，不同的模式下FSMC访问存储器地址时引脚输出的时序不一样，可选FSMC_ACCESS_MODE_A/B/C/D模式。一般来说控制SRAM时使用A模式。</p>
</blockquote>
<h3 id="SRAM初始化结构体"><a href="#SRAM初始化结构体" class="headerlink" title="SRAM初始化结构体"></a>SRAM初始化结构体</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* @brief  FSMC NOR/SRAM Init structure definition</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">   <span class="keyword">uint32_t</span> NSBank;                <span class="comment">/*设置要控制的Bank区域 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> DataAddressMux;        <span class="comment">/*设置地址总线与数据总线是否复用 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> MemoryType;          <span class="comment">/*设置存储器的类型 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> MemoryDataWidth;     <span class="comment">/*设置存储器的数据宽度*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> BurstAccessMode;        <span class="comment">/*设置是否支持突发访问模式，只支持同步类型的存储器 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> WaitSignalPolarity;  <span class="comment">/*设置等待信号的极性*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> WrapMode;            <span class="comment">/*设置是否支持对齐的突发模式 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> WaitSignalActive;    <span class="comment">/*配置等待信号在等待前有效还是等待期间有效 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> WriteOperation;      <span class="comment">/*设置是否写使能 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> WaitSignal;          <span class="comment">/*设置是否使能等待状态插入 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> ExtendedMode;        <span class="comment">/*设置是否使能扩展模式 */</span></span><br><span class="line">   <span class="keyword">uint32_t</span> WriteBurst;          <span class="comment">/*设置是否使能写突发操作*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> AsynchronousWait;    <span class="comment">/*设置是否使能等待信号*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> ContinuousClock;     <span class="comment">/*设置是否使能FMC时钟输出到外部存储设备*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> WriteFifo;           <span class="comment">/*设置是否使能FIFO*/</span></span><br><span class="line">   <span class="keyword">uint32_t</span> PageSize;            <span class="comment">/*指定页的大小*/</span></span><br><span class="line">   <span class="comment">/*当不使用扩展模式时，本参数用于配置读写时序，否则用于配置读时序*/</span></span><br><span class="line">   FSMC_NORSRAM_TimingTypeDef* FSMC_ReadWriteTimingStruct;</span><br><span class="line">   <span class="comment">/*当使用扩展模式时，本参数用于配置写时序*/</span></span><br><span class="line">   FSMC_NORSRAM_TimingTypeDef * FSMC_WriteTimingStruct;</span><br><span class="line">&#125; FSMC_NORSRAM_InitTypeDef;</span><br></pre></td></tr></table></figure>
<ol>
<li>NSBank</li>
</ol>
<blockquote>
<p>本成员用于选择FSMC映射的存储区域，它的可选参数以及相应的内核地址映射范围见表 26‑4。</p>
<p>表 26‑4 可以选择的存储器区域及区域对应的地址范围</p>
</blockquote>
<table>
<thead>
<tr>
<th>可以输入的宏</th>
<th>对应的地址区域</th>
</tr>
</thead>
<tbody><tr>
<td>FSMC_Bank1_NORSRAM1</td>
<td>0x60000000-0x63FFFFFF</td>
</tr>
<tr>
<td>FSMC_Bank1_NORSRAM2</td>
<td>0x64000000-0x67FFFFFF</td>
</tr>
<tr>
<td>FSMC_Bank1_NORSRAM3</td>
<td>0x68000000-0x6BFFFFFF</td>
</tr>
<tr>
<td>FSMC_Bank1_NORSRAM4</td>
<td>0x6C000000-0x6FFFFFFF</td>
</tr>
</tbody></table>
<ol>
<li>DataAddressMux</li>
</ol>
<blockquote>
<p>本成员用于设置地址总线与数据总线是否复用(FSMC_DATA_ADDRESS_MUX_DISABLE /DISABLE)，在控制NOR FLASH时，可以地址总线与数据总线可以分时复用，以减少使用STM32信号线的数量。</p>
</blockquote>
<ol>
<li>MemoryType</li>
</ol>
<blockquote>
<p>本成员用于设置要控制的存储器类型，它支持控制的存储器类型为SRAM、PSRAM以及NOR FLASH(FSMC_MEMORY_TYPE_SRAM/PSRAM/NOR)。</p>
</blockquote>
<ol>
<li>MemoryDataWidth</li>
</ol>
<blockquote>
<p>本成员用于设置要控制的存储器的数据宽度，可选择设置成8或16位(FSMC_NORSRAM_MEM_BUS_WIDTH_8/16/32)。</p>
</blockquote>
<ol>
<li>BurstAccessMode</li>
</ol>
<blockquote>
<p>本成员用于设置是否使用突发访问模式(FSMC_BURST_ACCESS_MODE_DISABLE /DISABLE)，突发访问模式是指发送一个地址后连续访问多个数据，非突发模式下每访问一个数据都需要输入一个地址，仅在控制同步类型的存储器时才能使用突发模式。</p>
</blockquote>
<ol>
<li>AsynchronousWait</li>
</ol>
<blockquote>
<p>本成员用于设置是否使能在同步传输时使用的等待信号(FSMC_ASYNCHRONOUS_WAIT_DISABLE /DISABLE)，在控制同步类型的NOR或PSRAM时，存储器可以使用FSMC_NWAIT引脚通知STM32需要等待。</p>
</blockquote>
<ol>
<li>WaitSignalPolarity</li>
</ol>
<blockquote>
<p>本成员用于设置等待信号的有效极性，即要求等待时，使用高电平还是低电平(FSMC_WAIT_SIGNAL_POLARITY_LOW /HIGH)。</p>
</blockquote>
<ol>
<li>FSMC_WrapMode</li>
</ol>
<blockquote>
<p>本成员用于设置是否支持把非对齐的AHB突发操作分割成2次线性操作(FSMC_WRAP_MODE_DISABLE /ENABLE)，该配置仅在突发模式下有效。</p>
</blockquote>
<ol>
<li>WaitSignalActive</li>
</ol>
<blockquote>
<p>本成员用于配置在突发传输模式时，决定存储器是在等待状态之前的一个数据周期有效还是在等待状态期间有效(FSMC_WAIT_TIMING_BEFORE_WS / FSMC_WAIT_TIMING_DURING_WS)。</p>
</blockquote>
<ol>
<li>WriteOperation</li>
</ol>
<blockquote>
<p>这个成员用于设置是否写使能(FSMC_WRITE_OPERATION_DISABLE /ENABLE)，禁止写使能的话FSMC只能从存储器中读取数据，不能写入。</p>
</blockquote>
<ol>
<li>WaitSignal</li>
</ol>
<blockquote>
<p>本成员用于设置当存储器处于突发传输模式时，是否允许通过NWAIT信号插入等待状态(FSMC_WAIT_SIGNAL_ENABLE /DISABLE)。</p>
</blockquote>
<ol>
<li>ExtendedMode</li>
</ol>
<blockquote>
<p>本成员用于设置是否使用扩展模式(FSMC_EXTENDED_MODE_ENABLE /DISABLE)，在非扩展模式下，对存储器读写的时序都只使用FSMC_BCR寄存器中的配置，即下面的FSMC_ReadWriteTimingStruct结构体成员；在扩展模式下，对存储器的读写时序可以分开配置，读时序使用FSMC_BCR寄存器，写时序使用FSMC_BWTR寄存器的配置，即下面的FSMC_WriteTimingStruct结构体。</p>
</blockquote>
<h3 id="读时序配置例子"><a href="#读时序配置例子" class="headerlink" title="读时序配置例子"></a>读时序配置例子</h3><p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/image121.jpeg"></p>
<blockquote>
<h3 id="表-SRAM的读操作参数-时间要求摘自《IS62WV51216》规格书"><a href="#表-SRAM的读操作参数-时间要求摘自《IS62WV51216》规格书" class="headerlink" title="表 SRAM的读操作参数(时间要求摘自《IS62WV51216》规格书)"></a>表 SRAM的读操作参数(时间要求摘自《IS62WV51216》规格书)</h3></blockquote>
<table>
<thead>
<tr>
<th>时间参数</th>
<th>SRAM要求</th>
<th>说明</th>
<th>FSMC配置要求表达式</th>
</tr>
</thead>
<tbody><tr>
<td>tRC</td>
<td>不小于55ns</td>
<td>读操作周期</td>
<td>ADDSET+1+DATAST+1+2 &gt; 55ns</td>
</tr>
<tr>
<td>小于tLZCE</td>
<td>SRAM无给出要求</td>
<td>从发出地址到给出读使能信号的时间</td>
<td>ADDSET+1 &gt; 0 ns</td>
</tr>
<tr>
<td>tDOE</td>
<td>最迟不大于25ns</td>
<td>从接收到读使能信号至给出有效数据的时间</td>
<td>DATAST+1 &gt; 25 ns</td>
</tr>
</tbody></table>
<p>​        根据FSMC配置表达式的配置要求把时间单位1/72微秒(即1000/72纳秒)代入，可求得ADDSET = 0，DATAST=1时即可符合要求。如：</p>
<p>​        tRC=ADDSET+1+DATAST+1+2 =( 0+1+8+1+2 )*1000/168 = 71.4 ns &gt; 55 ns</p>
<p>​        tDOE=DATAST+1 = (8+1)*1000/168 = 53.5 &gt; 25 ns</p>
<p>​        可看出本实验中的配置有充足的裕量，裕量较大，可确保访问正确，但会导致访问速度变慢，可根据实际需要进行测试调整，保证访问正确的前提下可提高访问速度。</p>
<h3 id="写时序配置例子"><a href="#写时序配置例子" class="headerlink" title="写时序配置例子"></a>写时序配置例子</h3><p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/image131.jpeg"></p>
<p>表 SRAM的写操作参数(时间要求摘自《IS62WV51216》规格书)</p>
<table>
<thead>
<tr>
<th>时间参数</th>
<th>SRAM要求</th>
<th>说明</th>
<th>FSMC配置要求表达式</th>
</tr>
</thead>
<tbody><tr>
<td>tWC</td>
<td>大于55ns</td>
<td>写操作周期</td>
<td>ADDSET+1+DATAST+1 &gt; 55ns</td>
</tr>
<tr>
<td>tSA</td>
<td>无要求</td>
<td>地址建立时间</td>
<td>ADDSET+1 &gt; 0 ns</td>
</tr>
<tr>
<td>tPWB</td>
<td>最早最不小于40ns</td>
<td>从接收到写使能信号到对数据采样的时间</td>
<td>DATAST+1 &gt; 40 ns</td>
</tr>
</tbody></table>
<p>​        根据FSMC配置表达式的配置要求把时间单位1/72微秒(即1000/72纳秒)代入，可求得ADDSET = 0，DATAST=2时即可符合要求。如：</p>
<p>​        tWC = ADDSET+1+DATAST+1 =( 0+1+8+1 )*1000/168 = 59.5 ns &gt; 55 ns</p>
<p>​        tPWB = DATAST+1 = (8+1) *1000 / 168 = 53.5 &gt; 40 ns</p>
<p>​        把计算得的参数赋值到时序结构体中的AddressSetupTime（即ADDSET的值）及DataSetupTime（即DATAST的值）中，然后再把时序结构体作为指针赋值到FSMC初始化结构体中，作为读写的时序参数，最后再调用FSMC_NORSRAMInit函数即可把参数写入到相应的寄存器中。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/23/%E6%98%93%E5%A4%B1%E6%80%A7%E5%AD%98%E5%82%A8%E5%99%A8%E4%BB%8B%E7%BB%8D/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/23/%E6%98%93%E5%A4%B1%E6%80%A7%E5%AD%98%E5%82%A8%E5%99%A8%E4%BB%8B%E7%BB%8D/" class="post-title-link" itemprop="url">易失性存储器介绍</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-23 20:44:14" itemprop="dateCreated datePublished" datetime="2022-10-23T20:44:14+08:00">2022-10-23</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/23/%E6%98%93%E5%A4%B1%E6%80%A7%E5%AD%98%E5%82%A8%E5%99%A8%E4%BB%8B%E7%BB%8D/" class="post-meta-item leancloud_visitors" data-flag-title="易失性存储器介绍" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/23/%E6%98%93%E5%A4%B1%E6%80%A7%E5%AD%98%E5%82%A8%E5%99%A8%E4%BB%8B%E7%BB%8D/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/23/%E6%98%93%E5%A4%B1%E6%80%A7%E5%AD%98%E5%82%A8%E5%99%A8%E4%BB%8B%E7%BB%8D/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://doc.embedfire.com/mcu/stm32/f4/hal_general/zh/latest/doc/chapter22/chapter22.html">https://doc.embedfire.com/mcu/stm32/f4/hal_general/zh/latest/doc/chapter22/chapter22.html</a></p>
<p>​        <img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20221023204617.png" style="zoom:75%;"></p>
<h3 id="1-RAM存储器"><a href="#1-RAM存储器" class="headerlink" title="1 RAM存储器"></a>1 RAM存储器</h3><p>​        RAM是“Random Access Memory”的缩写，被译为随机存储器。所谓“随机存取”，指的是当存储器中的消息被读取或写入时，所需要的时间与这段信息所在的位置无关。这个词的由来是因为早期计算机曾使用磁鼓作为存储器，磁鼓是顺序读写设备，而RAM可随读取其内部任意地址的数据，时间都是相同的，因此得名。实际上现在RAM已经专门用于指代作为计算机内存的易失性半导体存储器。</p>
<p>​        根据RAM的存储机制，又分为动态随机存储器DRAM(Dynamic RAM)以及静态随机存储器SRAM(Static RAM)两种。</p>
<h4 id="1-1-DRAM"><a href="#1-1-DRAM" class="headerlink" title="1.1 DRAM"></a>1.1 DRAM</h4><p>​        动态随机存储器DRAM的存储单元以电容的电荷来表示数据，有电荷代表1，无电荷代表0，见下图。 但时间一长，代表1的电容会放电，代表0的电容会吸收电荷，因此它需要定期刷新操作，这就是“动态(Dynamic)”一词所形容的特性。刷新操作会对电容进行检查，若电量大于满电量的1/2，则认为其代表1，并把电容充满电；若电量小于1/2，则认为其代表0，并把电容放电，藉此来保证数据的正确性。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20221023204907.png" style="zoom:80%;">

<h5 id="1-1-1-SDRAM"><a href="#1-1-1-SDRAM" class="headerlink" title="1.1.1 SDRAM"></a>1.1.1 SDRAM</h5><p>​        根据DRAM的通讯方式，又分为同步和异步两种，这两种方式根据通讯时是否需要使用时钟信号来区分。下图是一种利用时钟进行同步的通讯时序，它在时钟的上升沿表示有效数据。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20221023205016.png" style="zoom:67%;">

<p>​        由于使用时钟同步的通讯速度更快，所以同步DRAM使用更为广泛，这种DRAM被称为SDRAM(Synchronous DRAM)。</p>
<h5 id="1-1-2-DDR-SDRAM"><a href="#1-1-2-DDR-SDRAM" class="headerlink" title="1.1.2 DDR SDRAM"></a>1.1.2 DDR SDRAM</h5><p>​        为了进一步提高SDRAM的通讯速度，人们设计了DDR SDRAM存储器(Double Data Rate SDRAM)。 它的存储特性与SDRAM没有区别，但SDRAM只在上升沿表示有效数据，在1个时钟周期内，只能表示1个有数据； 而DDR SDRAM在时钟的上升沿及下降沿各表示一个数据，也就是说在1个时钟周期内可以表示2位数据，在时钟频率同样的情况下， 提高了一倍的速度。至于DDRII和DDRIII，它们的通讯方式并没有区别，主要是通讯同步时钟的频率提高了。</p>
<p>​        当前个人计算机常用的内存条是DDRIII SDRAM存储器，在一个内存条上包含多个DDRIII SDRAM芯片。</p>
<h4 id="1-2-SRAM"><a href="#1-2-SRAM" class="headerlink" title="1.2 SRAM"></a>1.2 SRAM</h4><p>​        静态随机存储器SRAM的存储单元以锁存器来存储数据，见下图。 这种电路结构不需要定时刷新充电，就能保持状态(当然，如果断电了，数据还是会丢失的)，所以这种存储器被称为“静态(Static)”RAM。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20221023205157.png" style="zoom:67%;">

<p>​        同样地，SRAM根据其通讯方式也分为同步(SSRAM)和异步SRAM，相对来说，<strong>异步SRAM用得比较广泛</strong>。</p>
<h4 id="1-3-DRAM与SRAM的应用场合"><a href="#1-3-DRAM与SRAM的应用场合" class="headerlink" title="1.3 DRAM与SRAM的应用场合"></a>1.3 DRAM与SRAM的应用场合</h4><p>​        对比DRAM与SRAM的结构，可知DRAM的结构简单得多，所以生产相同容量的存储器，DRAM的成本要更低，且集成度更高。 而DRAM中的电容结构则决定了它的存取速度不如SRAM，特性对下表。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20221023205319.png" style="zoom:67%;">

<p>​        所以在实际应用场合中，SRAM一般只用于CPU内部的高速缓存(Cache)，而外部扩展的内存一般使用DRAM。在STM32系统的控制器中，只有STM32F429型号或更高级的芯片才支持扩展SDRAM，其它型号如STM32F1、STM32F2及STM32F407等型号只能扩展SRAM。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/17/FSMC%20HADDR%E5%92%8CFSMC_A%E5%AF%B9%E5%BA%94%E9%97%AE%E9%A2%98/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/17/FSMC%20HADDR%E5%92%8CFSMC_A%E5%AF%B9%E5%BA%94%E9%97%AE%E9%A2%98/" class="post-title-link" itemprop="url">FSMC HADDR和FSMC_A对应问题</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-17 21:50:15" itemprop="dateCreated datePublished" datetime="2022-10-17T21:50:15+08:00">2022-10-17</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/17/FSMC%20HADDR%E5%92%8CFSMC_A%E5%AF%B9%E5%BA%94%E9%97%AE%E9%A2%98/" class="post-meta-item leancloud_visitors" data-flag-title="FSMC HADDR和FSMC_A对应问题" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/17/FSMC%20HADDR%E5%92%8CFSMC_A%E5%AF%B9%E5%BA%94%E9%97%AE%E9%A2%98/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/17/FSMC%20HADDR%E5%92%8CFSMC_A%E5%AF%B9%E5%BA%94%E9%97%AE%E9%A2%98/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>参考原文：<a target="_blank" rel="noopener" href="https://www.cnblogs.com/yeshenmeng/p/15597980.html">https://www.cnblogs.com/yeshenmeng/p/15597980.html</a></p>
<p>​                   <a target="_blank" rel="noopener" href="https://blog.csdn.net/ABAP_Brave/article/details/53080703">https://blog.csdn.net/ABAP_Brave/article/details/53080703</a></p>
<p>​                   <a target="_blank" rel="noopener" href="https://blog.csdn.net/alalalalaya/article/details/110670881">https://blog.csdn.net/alalalalaya/article/details/110670881</a></p>
<h3 id="1-FSMC存储块"><a href="#1-FSMC存储块" class="headerlink" title="1.FSMC存储块"></a>1.FSMC存储块</h3><p>​        FSMC的外部设备地址映像:STM32的FSMC将外部存储器划分为固定大小为256M字节的四个存储块：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210172156797.png" style="zoom:67%;">

<p>​        FSMC分为4块,每块256M字节又被划分为4*64,即四个片选<br>​        NOR / PSRAM使用块1,共256M<br>        NAND闪存使用块2,3,共512M<br>​        PC卡使用块4,共256M</p>
<h3 id="2-存储块1-Bank1-介绍"><a href="#2-存储块1-Bank1-介绍" class="headerlink" title="2.存储块1(Bank1)介绍"></a>2.存储块1(Bank1)介绍</h3><p>​        STM32的FSMC存储块1（Bank1）用于驱动NOR FLASH/SRAM/PSRAM<br>​        Bank1被分为4个区，每个区管理64M字节空间，每个区都有独立的寄存器对所连接的存储器进行配置。<br>​        Bank1的256M字节空间由28根地址线（HADDR[27:0]）寻址。 <strong>这里HADDR，是内部AHB地址总线</strong>，<br>​        **HADDR[25:0]来自外部存储器地址FSMC_A[25:0]**，而HADDR[26:27]对4个区进行寻址。</p>
<p>​        如下图所示:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210172210099.png" style="zoom:77%;">

<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">说明:</span><br><span class="line">     HADDR[<span class="number">27</span>:<span class="number">26</span>]是不可手动配置的,当选择所在区后会自动赋值</span><br><span class="line"></span><br><span class="line">注意:</span><br><span class="line">     <span class="number">1</span>,当Bank1接 <span class="number">8</span>位宽度存储器时：HADDR[<span class="number">25</span>:<span class="number">0</span>] -&gt; FSMC_A[<span class="number">25</span>:<span class="number">0</span>]</span><br><span class="line">     <span class="number">2</span>,当Bank1接<span class="number">16</span>位宽度存储器时：HADDR[<span class="number">25</span>:<span class="number">1</span>] -&gt; FSMC_A[<span class="number">24</span>:<span class="number">0</span>]</span><br><span class="line"></span><br><span class="line">        由于内部每个地址对应一个字节,外部设备<span class="number">16</span>位宽,FSMC的一个地址对应两个字节</span><br><span class="line">        即:</span><br><span class="line">             <span class="number">0000</span>对应FSMC_A[<span class="number">0</span>]=<span class="number">0</span>   (<span class="number">2</span>字节)</span><br><span class="line">             <span class="number">0010</span>对应FSMC_A[<span class="number">0</span>]=<span class="number">1</span>   (<span class="number">2</span>字节)</span><br><span class="line">             <span class="number">0100</span>对应FSMC_A[<span class="number">1</span>]=<span class="number">1</span>   (<span class="number">2</span>字节)</span><br><span class="line"></span><br><span class="line">        所以对应关系需要除以<span class="number">2</span>,内部右移一位对齐</span><br><span class="line">        此时最低位没用,访问最低位需要使用UB/LB</span><br></pre></td></tr></table></figure>
<h3 id="3-FSMC-HADDR和FSMC-A对应关系"><a href="#3-FSMC-HADDR和FSMC-A对应关系" class="headerlink" title="3.FSMC HADDR和FSMC_A对应关系"></a>3.FSMC HADDR和FSMC_A对应关系</h3><p><strong>问题：</strong></p>
<p>当外部存储器是8位数据宽度时， HADDR[25:0]与FSMC_A[25:0]对应相连</p>
<p>当外部存储器是16位数据宽度时，HADDR[25:1]与FSMC_A[24:0]对应相连，HADDR[0]未接</p>
<p>或者看下面这个实例：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210172225064.png" style="zoom:67%;">

<p><strong>ARM芯片的A1引脚连接的是SRAM芯片的A0地址引脚</strong>。由图可以看出，SRAM芯片的数据总线是16位宽，即一次传输2个字节的数据。因此，我们可以这样理解，即一个地址空间其实对应着2个字节的数据。</p>
<p><strong>原因：</strong></p>
<p>​        首先，CPU中一个地址只能存储一个字节的数据，而当CPU通过地址线访问外部存储器的一个地址时，如果外部储存器的一个地址的数据刚好是八位时（即一个字节），访问一次就可接收过来；但是，当外部存储器的一个地址里存的是16位数据时（即两个字节），CPU就开始傻眼了，“我访问你一次，你竟然给我两个字节的数据！！！”（如下图所示）</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210172230207.png" style="zoom:67%;">

<p>​        然后，CPU为了解决这个问题，只能够再派一个地址去访问外部存储器的同一个地址，把剩下的那个字节也接收过来，之后再接着访问外部存储器的第二个地址，依此类推。。。在此过程中，CPU如果还是把地址线一对一地连接到外部存储器上，那就做不到让自己的第二个地址还继续访问同一个地址了。。。</p>
<p>​        于是，人们帮了CPU一把，让它每一回访问时还是照旧把自己内部的地址按二进制拆分放到HADDR的0~25上（如下图）</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210172233844.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210172234128.png" style="zoom:67%;">

<p>​        由图片红色部分可知，如读取外部存储器地址0中的#a、#b数据，CPU先发送地址0、再发送地址1。站在CPU的角度，它以为自己发送了两个不一样的地址（地址0、地址1）到外部存储器，然后，到了FSMC_A一端，人们选择性地去掉HADDR[0]，然后才把把剩余的25根依次接到FSMC_A上。然而对于外部存储器来说，它只收到读地址0的数据，所以外部存储器就把#a、#b的数据返回给CPU。即对于16位数据宽度的外部存储器来说，因为CPU一个地址存储1个字节数据，外部16位数据宽度存储器1个地址存储2个字节数据，所以CPU的地址0、1对应外部存储器的地址0，地址2、3对应外部存储器的地址1，以此类推。</p>
<p>​        在CPU那边，它对人们把HADDR[0]不接到FSMC上是不知情的，所以，它还是照旧把地址逐次增一地去访问，也还是发出一个地址读回一个字节，但是它不知道的是，自己每发两个地址都会停留在外部存储器的同一个地址上，所以最终，同一个地址上的两个字节都会被CPU读走。。。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/13/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E5%AD%98%E6%94%BE%E6%96%B9%E5%BC%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/13/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E5%AD%98%E6%94%BE%E6%96%B9%E5%BC%8F/" class="post-title-link" itemprop="url">二维数组在内存中的存放方式</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-13 23:19:21" itemprop="dateCreated datePublished" datetime="2022-10-13T23:19:21+08:00">2022-10-13</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/13/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E5%AD%98%E6%94%BE%E6%96%B9%E5%BC%8F/" class="post-meta-item leancloud_visitors" data-flag-title="二维数组在内存中的存放方式" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/13/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E5%AD%98%E6%94%BE%E6%96%B9%E5%BC%8F/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/13/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84%E5%9C%A8%E5%86%85%E5%AD%98%E4%B8%AD%E7%9A%84%E5%AD%98%E6%94%BE%E6%96%B9%E5%BC%8F/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        下面的内容来自于互联网，原文链接：<a target="_blank" rel="noopener" href="https://cooc.cqmu.edu.cn/Course/KnowledgePoint/4984.aspx?AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1">https://cooc.cqmu.edu.cn/Course/KnowledgePoint/4984.aspx?AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1</a></p>
<p>​        二维数组在概念上是二维的，而存储器单元是按一维线性排列的。 如何在一维存储器中存放二维数组，可有两种方式：一种是按行排列， 即放完一行之后顺次放入第二行。另一种是按列排列， 即放完一列之后再顺次放入第二列。        </p>
<p>​        在C语言中，二维数组是<strong>按行排列的</strong>。 </p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210132327729.png" style="zoom:87%;">

<p>​        在图1中，按行顺次存放，先存放a[0]行，再存放a[1]行，最后存放a[2]行。每行中有四个元素也是依次存放。由于数组a说明为int类型，该类型占4个字节的内存空间，所以每个数组元素均占有4个字节。</p>
<p>​         假设数组a的起始地址为2000，则该二维数组在内存在的存放方式如图2所示。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210132330829.png" style="zoom:80%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/11/PC%E4%B8%8A%E8%BF%90%E8%A1%8CopenPowerlink%E4%BE%8B%E5%AD%90/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/11/PC%E4%B8%8A%E8%BF%90%E8%A1%8CopenPowerlink%E4%BE%8B%E5%AD%90/" class="post-title-link" itemprop="url">PC上运行openPowerlink例子</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-11 22:48:32" itemprop="dateCreated datePublished" datetime="2022-10-11T22:48:32+08:00">2022-10-11</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/11/PC%E4%B8%8A%E8%BF%90%E8%A1%8CopenPowerlink%E4%BE%8B%E5%AD%90/" class="post-meta-item leancloud_visitors" data-flag-title="PC上运行openPowerlink例子" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/11/PC%E4%B8%8A%E8%BF%90%E8%A1%8CopenPowerlink%E4%BE%8B%E5%AD%90/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/11/PC%E4%B8%8A%E8%BF%90%E8%A1%8CopenPowerlink%E4%BE%8B%E5%AD%90/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        硬件：两台PC，一台做主站，一台做从站，每台PC需要以太网网卡。</p>
<p>​        软件：<strong>需要安装winpcap</strong>，VS2008，openPOWERLINK源码(<a target="_blank" rel="noopener" href="http://sourceforge.net/projects/openpowerlink/files/">http://sourceforge.net/projects/openpowerlink/files/</a>)</p>
<h3 id="主站程序"><a href="#主站程序" class="headerlink" title="主站程序"></a>主站程序</h3><p>​        用 VS2008 打 开openPOWERLINK_v1.7.1\Examples\X86\Windows\VC9\demo_pcap 下的 demo_pcap.vcproj工程。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210112259107.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210112300759.png" style="zoom:67%;">

<p><strong>接收的时候：</strong></p>
<p>0x1402/0x01  主站接收PDO通道接收<strong>1号从站</strong>数据</p>
<p>0x1602/0x01   0x0008000000016200LL  主站将<strong>1号从站</strong>发来的数据放到自身的0x6200/0x01的object中</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210112305501.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210112306173.png" style="zoom:67%;">

<p><strong>发送的时候：</strong></p>
<p>0x1801/0x01   主站发送PDO通道发送数据给<strong>1号从站</strong></p>
<p>0x1A01/0x01   0x0008000000016000LL   主站将自身0x6000/0x01 object中数据发送给<strong>1号从站</strong>。</p>
<p>修改demo_main.c文件：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210112313545.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210112314540.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210112316014.png" style="zoom:67%;">

<h3 id="从站程序"><a href="#从站程序" class="headerlink" title="从站程序"></a>从站程序</h3><p>​        同样是打开 objdict.h 文件，然后进行修改。对于修改部分理解的方式和主站类似，这里就不再讲解了。</p>
<h3 id="Demo运行"><a href="#Demo运行" class="headerlink" title="Demo运行"></a>Demo运行</h3><p>​        将两台 PC 的网口用网线连接，运行主站和从站程序，主站产生如下输出。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210112326269.png" style="zoom:67%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/10/%E5%90%8C%E6%AD%A5%E9%80%9A%E4%BF%A1%E6%A8%A1%E5%9E%8BPDO%E7%9A%84%E9%80%9A%E4%BF%A1%E5%8F%82%E6%95%B0%E5%92%8C%E6%98%A0%E5%B0%84%E5%8F%82%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/10/%E5%90%8C%E6%AD%A5%E9%80%9A%E4%BF%A1%E6%A8%A1%E5%9E%8BPDO%E7%9A%84%E9%80%9A%E4%BF%A1%E5%8F%82%E6%95%B0%E5%92%8C%E6%98%A0%E5%B0%84%E5%8F%82%E6%95%B0/" class="post-title-link" itemprop="url">同步通信模型PDO的通信参数和映射参数</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-10 21:38:58" itemprop="dateCreated datePublished" datetime="2022-10-10T21:38:58+08:00">2022-10-10</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/10/%E5%90%8C%E6%AD%A5%E9%80%9A%E4%BF%A1%E6%A8%A1%E5%9E%8BPDO%E7%9A%84%E9%80%9A%E4%BF%A1%E5%8F%82%E6%95%B0%E5%92%8C%E6%98%A0%E5%B0%84%E5%8F%82%E6%95%B0/" class="post-meta-item leancloud_visitors" data-flag-title="同步通信模型PDO的通信参数和映射参数" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/10/%E5%90%8C%E6%AD%A5%E9%80%9A%E4%BF%A1%E6%A8%A1%E5%9E%8BPDO%E7%9A%84%E9%80%9A%E4%BF%A1%E5%8F%82%E6%95%B0%E5%92%8C%E6%98%A0%E5%B0%84%E5%8F%82%E6%95%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/10/%E5%90%8C%E6%AD%A5%E9%80%9A%E4%BF%A1%E6%A8%A1%E5%9E%8BPDO%E7%9A%84%E9%80%9A%E4%BF%A1%E5%8F%82%E6%95%B0%E5%92%8C%E6%98%A0%E5%B0%84%E5%8F%82%E6%95%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        PDO是process data object的缩写。简单地说， 可以理解为数据桢。在POWERLINK 通信过程中，如果某个节点需要将自己对象字典中的多个object周期性地发送出去，就需要将这些要发送的 object 组成一个数据桢，发送到网络上。这个数据桢，就称为 PDO。向外发送的PDO，称之为TPDO; 接收到的 PDO，称之为 RPDO。PDO的传输类型是连续的，不提供“基于事件”或“基于改变”传输类型，也就是无论实时数据是否有变化，PDO的数据都是周期性的发送，这一点有别于传统的CANopen。</p>
<p>​        看一个powerlink网络的例子：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102200459.png" style="zoom:57%;">

<p>​        在这个例子中，有主站（PLC）, 1 号从站 （IO 站）， 2 号从站（伺服驱动器），3号从站（传感器），这些设备共同组成一个网络。</p>
<p>​        这就涉及到一些问题：<br>​        1． 对于每一个设备他需要将自己的哪些 object 发送到网络上？<br>​        2． 这些 object 如何组成一个数据桢，即这些 object 在数据桢中的位置排列？<br>​        3． 由于 POWERLINK 支持交叉通信，也就是说上述例子中的伺服驱动器可以接收<br>来自 PLC 的数据，也能接收来自传感器和 IO 站的数据。伺服是否需要接收某个传感器和 IO 站的数据？以及接收哪些数据？<br>​        4． 每个设备该如何解析收到的数据包？</p>
<p>​        <strong>这些问题需要通过配置通信参数和映射参数来解决。</strong></p>
<p>​        <strong>通信参数</strong>：决定该节点需要接收来自哪个节点的数据，或者将数据发送给哪个节点。对于从节点，由于发送数据桢是广播的，因此不需要设置该参数；对于主站的发送数据桢 Preq，需要设置该参数，来标示该数据桢是发送给哪个从节点的。</p>
<p>​        <strong>映射参数</strong>：决定该节点如何组成要发送的数据包或者如何解析收到的数据包。也就是确定对象字典中的对象（Object）与数据包中数据段的对应关系。</p>
<p>​        每个 POWERLINK 节点接收和发送数据时，都有一组通信参数和映射参数来描述。</p>
<p>​        <strong>对于接收：</strong><br>​        0x1400-0x14ff：为通信参数<br>​        0x1600-0x16ff：为映射参数<br>​        通信参数和映射参数成对出现，一一对应。0x1400 与 0x1600 为一对；0x1401 与 0x1601为一对；0x14xx 与 0x16xx 为一对。</p>
<p>​        <strong>对于发送：</strong><br>​        0x1800-0x18ff：为通信参数<br>​        0x1A00-0x1Aff：为映射参数<br>​        通信参数和映射参数成对出现，一一对应。0x1800 与 0x1A00 为一对；0x1801 与 0x1A01为一对；0x18xx 与 0x1Axx 为一对。</p>
<h4 id="一、从站发送之通信参数-0x18XX"><a href="#一、从站发送之通信参数-0x18XX" class="headerlink" title="一、从站发送之通信参数(0x18XX)"></a>一、从站发送之通信参数(0x18XX)</h4><p>​        该参数描述此节点需要把自己的数据帧发送给网络中的哪个节点（根据节点号区分）。从我们前面讲的 POWERLINK 基本原理可知，每个从站在上报自己数据的时候，都是以广播的形式发送，也就是说从站发送数据的时候，发送的目标地址是 255。因此所有从节点的发送数据的通信参数都是255。</p>
<p>​        一个 POWERLINK 数据帧最大为 1500 个字节，节点在发送数据时，可以把很多参数打包成一个大的数据帧。所以在 POWERLINK 网络中，一个从节点每个循环周期只需要发送一个数据帧就够了。因此对于从节点，我们只需要实现并使用 0x1800 就够了。</p>
<h4 id="二、从站发送之映射参数-0x1AXX"><a href="#二、从站发送之映射参数-0x1AXX" class="headerlink" title="二、从站发送之映射参数(0x1AXX)"></a>二、从站发送之映射参数(0x1AXX)</h4><p>​        由于通信参数和映射参数成对出现，一一对应。0x1800 与 0x1A00 为一对；因此对于从节点，当你使用 0x1800 作为通信参数时，那么你就必须使用 0x1A00 作为映射参数。映射参数解决的是对象字典中的对象 Object（即参数）与数据帧中数据段的对应关系。对于发送来说，也就是如何将要发送的Object 组成一个数据帧。</p>
<p>​        如下图，描述了一个数据帧和一个对象字典中需要发送的对象。现在需要将这些要发送的参数，组成一个数据帧。<strong>也就是把每一个要发送的 Object 与某一个数据段建立映射关系,把 Object 的值放到数据帧中对应的字段</strong>。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102236876.png" style="zoom:60%;">

<p>​        假如我们想建立如下映射关系：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102237915.png" style="zoom:60%;">

<p>​        即：</p>
<p>​        对象 0x2000/02 放在数据帧偏移量为 0 的地方，长度为 16bits，</p>
<p>​        对象 0x6000/01 放在数据帧偏移量为 16 的地方，长度为 16bits；</p>
<p>​        对象 0x6000/02 放在数据帧偏移量为 32 的地方，长度为 8bits；</p>
<p>​        对象 0x2000/01 放在数据帧偏移量为 40 的地方，长度为 16bits；</p>
<p>​        为此，我们需要将 0x1A00 的值配置如下：</p>
<p>​        0x1A00/0x01 值: 0x0010000000022000<br>​        0x1A00/0x02 值: 0x0010001000016000<br>​        0x1A00/0x03 值: 0x0008002000026000<br>​        0x1A00/0x04 值: 0x0010002800012000</p>
<p>​        下面来详细解释一下第一句话的意思，“0x1A00/0x01 值 0x0010000000022000”</p>
<p>​        <strong>0x1A00/0x01 是用来描述第一个 Object 与数据帧中字段的映射关系的参数</strong>，把他的值设为0x0010000000022000，意思是将索引为 0x2000 子索引为 0x02 的对象映射到数据帧偏移量为 0x0000 (数据帧开头)的地方，长度为 16bits。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102253183.png" style="zoom:67%;">

<h4 id="三、从站接收之通信参数-0x14XX"><a href="#三、从站接收之通信参数-0x14XX" class="headerlink" title="三、从站接收之通信参数(0x14XX)"></a>三、从站接收之通信参数(0x14XX)</h4><p>​        该参数描述了此节点需要接收来自哪个节点的数据。从前面讲述的 POWERLINK 基本原理可知，POWERLINK 支持交叉通信，因此每一个节点都可以接收来自另外一个或多个节点的数据。<strong>所以一个节点可以有多个接收通道。</strong>例如 0x1400 是一个通道，接收来自主节点的数据，那么就把 0x1400/0x01 的值设为 0（<strong>默认值设为 0，表示接收来自主站的请求数据</strong>）；0x1401 是一个通道，接收来自 3 号节点的数据，那么就把 0x1401/0x01 的值设为 3，这样该节点在同一个循环周期里既接收来自主站的数据，也接收来自 3 号节点的数据。</p>
<h4 id="四、从站接收之映射参数-0x16XX"><a href="#四、从站接收之映射参数-0x16XX" class="headerlink" title="四、从站接收之映射参数(0x16XX)"></a>四、从站接收之映射参数(0x16XX)</h4><p>​        由于通信参数和映射参数成对出现，一一对应。0x1400 与 0x1600 为一对，0x1401 与0x1601 为一对…；因此对于从节点，当你使用 0x1400 作为通信参数时，那么你就必须使用0x1600 作为映射参数。映射参数解决的是对象字典中的对象 Object（即参数）与数据帧中数据段的对于关系。对于接收来说，也就是如何将一个数据帧进行解析。<strong>因为某个节点发来的数据，往往是多个 Object 打包在一起的，接收方需要知道自己应该接收数据帧的哪一段或者哪几段，数据长度多长</strong>。</p>
<p>​        如下图，描述了一个数据帧，和对象字典中的对象。现在需要将收到的数据帧中的数据段和对象字典中的 Object 建立映射关系。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102305899.png" style="zoom:67%;">

<p>​        假如我们想建立如下映射关系：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102306766.png" style="zoom:67%;">

<p>​        即接收到的数据帧中数据段与 Object 的映射关系：<br>​        数据帧偏移量为 0，长度为 16bits，这段数据被截取放到对象 0x2000/02；<br>​        数据帧偏移量为 16，长度为 16bits，这段数据被截取放到对象 0x6000/01；<br>​        数据帧偏移量为 32，长度为 8bits，这段数据被截取放到对象 0x6000/02；<br>​        数据帧偏移量为 40，长度为 16bits，这段数据被截取放到对象 0x2000/01。</p>
<p>​        为此，我们需要将 0x1600 的值配置如下：<br>​        0x1600/0x01 值： 0x0010000000022000<br>​        0x1600/0x02 值： 0x0010001000016000<br>​        0x1600/0x03 值： 0x0008002000026000<br>​        0x1600/0x04 值： 0x0010002800012000</p>
<p>​        下面来详细解释第二句话的意思，“0x1600/0x02 值 0x0010001000016000”。</p>
<p>​        0x1600/0x02 是用来描述第二个 Object 与数据帧中字段的映射关系的参数，把他的值设为 0x0010001000016000，意思是数据帧中偏移量为 0x0010（第 16 bit 开始），长度为 0x0010（16bits）的这段数据映射到索引为 0x6000 子索引为 0x01 的对象。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102312148.png" style="zoom:67%;">

<h4 id="五、主站发送参数的配置"><a href="#五、主站发送参数的配置" class="headerlink" title="五、主站发送参数的配置"></a>五、主站发送参数的配置</h4><p>​        主站和从站的区别：每个循环周期，从站只需要发送一个 TPDO 的数据帧。</p>
<p>​        <strong>而主站如果基于请求/应答模式，一个循环周期需要向网络中所有的节点都发送一次请求数据帧 Preq，而且相应的也会收到从站的回复 Pres</strong>，一个 Preq 数据帧就是一个 TPDO,而一个 Pres 数据帧，就是一个 RPDO。<strong>这也就意味着主站在发送时，需要有多个发送 TPDO的通道；在接收时，需要有多个接收 RPDO 的通道</strong>。举例来说，假如一个系统里，有 1 个主节点和 3 个从节点。此时主站需要 3 个发送通道和 3 个接收通道。</p>
<p>​        对于主站的发送需要如下配置：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102327765.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102328621.png" style="zoom:60%;">

<p>​        对于接收需要如下配置：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210102328225.png" style="zoom:60%;">

<p>​        注意：PDO 的配置不支持动态变化， 一旦配置好了网络参数和映射参数，进入到同步通信阶段，网络中的各个节点就按照设定的参数，来组建数据桢以及解析数据桢。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/10/powerlink%E4%B8%ADobject%E7%9A%84%E5%AE%9A%E4%B9%89%E4%BE%8B%E5%AD%90%E5%92%8C%E8%AE%BF%E9%97%AE%E6%96%B9%E5%BC%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/10/powerlink%E4%B8%ADobject%E7%9A%84%E5%AE%9A%E4%B9%89%E4%BE%8B%E5%AD%90%E5%92%8C%E8%AE%BF%E9%97%AE%E6%96%B9%E5%BC%8F/" class="post-title-link" itemprop="url">powerlink中object的定义例子和访问方式</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-10 19:23:48" itemprop="dateCreated datePublished" datetime="2022-10-10T19:23:48+08:00">2022-10-10</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/10/powerlink%E4%B8%ADobject%E7%9A%84%E5%AE%9A%E4%B9%89%E4%BE%8B%E5%AD%90%E5%92%8C%E8%AE%BF%E9%97%AE%E6%96%B9%E5%BC%8F/" class="post-meta-item leancloud_visitors" data-flag-title="powerlink中object的定义例子和访问方式" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/10/powerlink%E4%B8%ADobject%E7%9A%84%E5%AE%9A%E4%B9%89%E4%BE%8B%E5%AD%90%E5%92%8C%E8%AE%BF%E9%97%AE%E6%96%B9%E5%BC%8F/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/10/powerlink%E4%B8%ADobject%E7%9A%84%E5%AE%9A%E4%B9%89%E4%BE%8B%E5%AD%90%E5%92%8C%E8%AE%BF%E9%97%AE%E6%96%B9%E5%BC%8F/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        在POWERLINK对OD(对象字典)的定义和声明在objdict.h文件中。这个文件采用宏定义的方式，定义了一个数据结构，如下图:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20221010192506.png" style="zoom:67%;">

<p>​        下面再看一个object定义的例子：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">EPL_OBD_BEGIN_INDEX_RAM(<span class="number">0x6000</span>, <span class="number">0x02</span>, <span class="literal">NULL</span>)</span><br><span class="line">	EPL_OBD_SUBINDEX_RAM_VAR(<span class="number">0x6000</span>, <span class="number">0x00</span>, kEplObdTypUInt8, kEplObdAccConst, tEplObdUnsigned8, number_of_entries, <span class="number">0x1</span>)</span><br><span class="line">	EPL_OBD_SUBINDEX_RAM_USERDEF(<span class="number">0x6000</span>, <span class="number">0x01</span>, kEplObdTypUInt8, kEplObdAccVPR, tEplObdUnsigned8, Sendb1, <span class="number">0x0</span>)</span><br><span class="line">EPL_OBD_END_INDEX(<span class="number">0x6000</span>)</span><br></pre></td></tr></table></figure>
<p><strong>解释：</strong></p>
<p>（1）EPL_OBD_BEGIN_INDEX_RAM(0x6000, 0x02, NULL)是 object 的头，0x02 是指它有两个子 object； NULL 是回调函数指针，对于简单应用，这里不用考虑。。</p>
<p>（2）EPL_OBD_END_INDEX(0x6000)是 object 的尾。这里的 0x6000 是这个 object 的索引；</p>
<p>（3）EPL_OBD_SUBINDEX_RAM_VAR(0x6000, 0x00, kEplObdTypUInt8, kEplObdAccConst, tEplObdUnsigned8, number_of_entries, 0x1) <strong>是第一个子object</strong>。其中 0x6000 是索引；0x00 是子索引； kEplObdTypUInt8 是对象类型，无符号 8 bits；kEplObdAccConst 是访问类型，这里为常量；tEplObdUnsigned8 是数据类型，无符号 8 bits；number_of_entries 是 object 的名字； <strong>0x1 是默认值，这里之所以默认值为 1 ，原因是通常子索引为 0x00 的子 object 用来表示有多少个有效的子 object</strong>。也就是除了子索引为0x00 的子 object 外，有多少个有效可用的子 object。这里我们看到除了子索引为 0x00 的 子 object 外，只有一个子索引为 0x01 的子 object。</p>
<p>（4）EPL_OBD_SUBINDEX_RAM_USERDEF(0x6000, 0x01, kEplObdTypUInt8, kEplObdAccVPR, tEplObdUnsigned8, Sendb1, 0x0)是第二个子 object ，其中 0x6000 是索引；0x01 是子索引；kEplObdTypUInt8 是对象类型，无符号 8 bits；kEplObdAccVPR 是访问类型，kEplObdAccVPR 的意思是变量,可映射为 PDO，只读的；tEplObdUnsigned8 是数据类型，无符号 8 bits；Sendb1 是 object 的名字； 0x0 是默认值。</p>
<p><strong>又一个例子：</strong></p>
<p>例如，我们要定义一个索引为0x6300的object， 他有4个子object。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">EPL_OBD_BEGIN_INDEX_RAM(<span class="number">0x6300</span>, <span class="number">0x04</span>, <span class="literal">NULL</span>)</span><br><span class="line">	EPL_OBD_SUBINDEX_RAM_VAR(<span class="number">0x6300</span>, <span class="number">0x00</span>, kEplObdTypUInt8,kEplObdAccConst, tEplObdUnsigned8, number_of_entries, <span class="number">0x3</span>)</span><br><span class="line">	EPL_OBD_SUBINDEX_RAM_USERDEF(<span class="number">0x6300</span>, <span class="number">0x01</span>, kEplObdTypUInt8, kEplObdAccVPR, tEplObdUnsigned8, input8, <span class="number">0x0</span>)</span><br><span class="line">	EPL_OBD_SUBINDEX_RAM_USERDEF(<span class="number">0x6300</span>, <span class="number">0x02</span>, kEplObdTypUInt16, kEplObdAccVPRW, tEplObdUnsigned16, output16, <span class="number">0x0</span>)</span><br><span class="line">	EPL_OBD_SUBINDEX_RAM_USERDEF(<span class="number">0x6300</span>, <span class="number">0x03</span>, kEplObdTypUInt32, kEplObdAccVPRW, tEplObdUnsigned32, output32, <span class="number">0x0</span>)</span><br><span class="line">EPL_OBD_END_INDEX(<span class="number">0x6300</span>)</span><br></pre></td></tr></table></figure>
<p><strong>解释：</strong></p>
<p>（1）EPL_OBD_BEGIN_INDEX_RAM(0x6300, 0x04, NULL)表示该 object 的索引为 0x6300，一共有 4 个子 object。</p>
<p>（2）EPL_OBD_SUBINDEX_RAM_VAR(0x6300, 0x00, kEplObdTypUInt8, kEplObdAccConst, tEplObdUnsigned8, number_of_entries, 0x3) 子索引为0x00的子object，默认值为3 ，表示下面有3个有效的子object。</p>
<p>（3）EPL_OBD_SUBINDEX_RAM_USERDEF(0x6300, 0x01, kEplObdTypUInt8, kEplObdAccVPR, tEplObdUnsigned8, input8, 0x0) 子索引为0x01的子object，数据类型为无符号8 bits ，访问类型为只读的，且可映射为PDO。</p>
<p>（4）EPL_OBD_SUBINDEX_RAM_USERDEF(0x6300, 0x02, kEplObdTypUInt16, kEplObdAccVPRW, tEplObdUnsigned16, output16, 0x0) 子索引为0x02的子object，数据类型为无符号16 bits ，访问类型（kEplObdAccVPRW）为可读且可写的，且可映射为PDO。</p>
<p>（5）EPL_OBD_SUBINDEX_RAM_USERDEF(0x6300, 0x03, kEplObdTypUInt32, kEplObdAccVPRW, tEplObdUnsigned32, output32, 0x0) 子索引为0x03的子object，数据类型为无符号32 bits ，访问类型为可读可写的，且可映射为PDO。</p>
<p><strong>应用程序对object的访问</strong></p>
<p>​        采用函数 EplApiLinkObject()，将自己定义的变量和 Object 连接起来，这样，当对象的值改变时，用户的变量的值也会改变，同样当用户的变量的值改变时，对象的值也会改变。因此应用程序只需要对自己定义的变量操作就可以了。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">EplApiLinkObject(<span class="keyword">unsigned</span> <span class="keyword">int</span> uiObjIndex_p, <span class="keyword">void</span>* pVar_p,<span class="keyword">unsigned</span> <span class="keyword">int</span>* puiVarEntries_p, tEplObdSize* pEntrySize_p,<span class="keyword">unsigned</span> <span class="keyword">int</span> uiFirstSubindex_p);</span><br></pre></td></tr></table></figure>
<p><strong>函数说明：</strong></p>
<p>（1）uiObjIndex_p：Object 的索引；</p>
<p>（2）uiFirstSubindex_p：Object 的第一个子索引（因为可以同时 link 多个 object，为了简单，你可以一次只 link 一个，此时这个参数就是 Object 的子索引）；</p>
<p>（3）pVar_p：应用程序定义的变量的地址；</p>
<p>（4）puiVarEntries_p：要 link 的 object 的个数；</p>
<p>（5）pEntrySize_p：要 link 的 object 的数据长度，单位为 byte；</p>
<p><strong>例子：</strong></p>
<p>例如，用户自己定义了一个变量 DigIn1，现在想要把他和对象 0x6000/0x01 link 起来,程序如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">uiVarEntries=<span class="number">1</span>;</span><br><span class="line">ObdSize=<span class="keyword">sizeof</span>(DigIn1);</span><br><span class="line">EplRet=EplApiLinkObject(<span class="number">0x6000</span>,&amp; DigIn1,&amp;uiVarEntries,&amp;ObdSize,<span class="number">0x01</span>);</span><br></pre></td></tr></table></figure>
<p>注意，用户自己定义的变量 DigIn1 的数据类型需要与 0x6000/0x01 这个 object 的数据类型相同。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/10/06/openCONFIGURATOR%20plugin%E5%AE%89%E8%A3%85/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/10/06/openCONFIGURATOR%20plugin%E5%AE%89%E8%A3%85/" class="post-title-link" itemprop="url">openCONFIGURATOR plugin安装</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-10-06 21:22:51" itemprop="dateCreated datePublished" datetime="2022-10-06T21:22:51+08:00">2022-10-06</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/10/06/openCONFIGURATOR%20plugin%E5%AE%89%E8%A3%85/" class="post-meta-item leancloud_visitors" data-flag-title="openCONFIGURATOR plugin安装" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/10/06/openCONFIGURATOR%20plugin%E5%AE%89%E8%A3%85/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/10/06/openCONFIGURATOR%20plugin%E5%AE%89%E8%A3%85/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        较早版本的openconfigurator只能在win xp 32bit下运行，所以这里尝试使用新版本的openconfigurator，新版本是作为eclipse的一个插件。安装的时候一开始选了一个版本比较新的eclipse，结果执行到一半的时候会报错，所以按照网上的教程选了一个别人用成功的版本。</p>
<p><strong>1.eclipse安装</strong></p>
<p>​        Eclipse官方提供安装版和绿色版两种版本，为了方便，我们就选择绿色版的。同时版本要选择合适的：<a target="_blank" rel="noopener" href="https://www.eclipse.org/downloads/packages/release/neon/3">https://www.eclipse.org/downloads/packages/release/neon/3</a></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210071629133.png" style="zoom:47%;">

<p><strong>2.点击Help-&gt;Eclipse Marketplace</strong></p>
<p>查找openCONFIGURATOR plugin，并且安装。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210062155310.png" style="zoom:57%;">

<p><strong>3.创建工程</strong></p>
<p>file-&gt;new-&gt;other</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210062204230.png" style="zoom:50%;">

<p>结果报错了：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210071640779.png" style="zoom:67%;">

<p>原因如下：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210071641687.png"></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202210072205534.png" style="zoom:67%;">

<p>安装这个即可。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/13/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/13/">13</a><span class="page-number current">14</span><a class="page-number" href="/page/15/">15</a><span class="space">&hellip;</span><a class="page-number" href="/page/29/">29</a><a class="extend next" rel="next" href="/page/15/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
